﻿using System;
using System.Text;

namespace UmbSearch2.UserControls
{
	public partial class SearchBox : System.Web.UI.UserControl
	{
		public int SearchResultNodeId { get; set; }
        
		protected void Page_Load(object sender, EventArgs e)
		{
			// keeps the last search query in the input control
			if(string.IsNullOrEmpty(txtInput.Text))
				txtInput.Text = Request["query"];
		}

		protected void btnSearch_Click(object sender, EventArgs e)
		{
			if (!string.IsNullOrEmpty(txtInput.Text))
			{
				string queryString = "?query=" + Server.UrlEncode(txtInput.Text);
				Response.Redirect(umbraco.library.NiceUrl(SearchResultNodeId) + queryString);
			}
		}

		
	}
}